<template>
  <g-details
    :detailData="inputData"
    :inputConfig="inputConfig"
    @pop="setdata"
    :rules="rules"
    ref="input"
  ></g-details>
</template>

<script>
import baseMixin from "@/mixins/BaseMixin";

export default {
  name: "otherDetails",
  mixins: [baseMixin],
  props: {
    inputData: {
      type: Object
    }
  },

  data () {
    return {
      inputConfig: [
          {
            type: "table",
            label: this.$t('bill.carrierCode'),
            props: "carrierkey",
            tableConfig: [
              {
                label: this.$t('config.carrier'),
                prop: "storerkey",
                input: "input"
              },
              { label: this.$t('config.company'), prop: "company", input: "input" },
              {
                label: this.$t('config.city'),
                prop: "city",
                input: "input"
              },
              { label: this.$t('config.provice'), prop: "state", input: "input" },
              {
                label: this.$t('config.postcode'),
                prop: "zip",
                input: "input"
              }
            ],
            url: "queryStorer/3/?/wmwhse1"
          },
          {
            type: "input",
            label: this.$t('in.carriername'),
            props: "carriername"
          },
          {
            type: "input",
            label: this.$t('config.address',{no:'1'}),
            props: "carrieraddress1"
          },
          {
            type: "input",
            label: this.$t('config.address',{no:'2'}),
            props: "carrieraddress2"
          },
          {
            type: "input",
            label: this.$t('config.city'),
            props: "carriercity"
          },
          {
            type: "input",
            label: this.$t('bill.province'),
            props: "carrierstate"
          },
          {
            type: "input",
            label: this.$t('config.postcode'),
            props: "carrierzip"
          },
          {
            type: "input",
            label: this.$t('in.carriername'),
            props: "carrierreference"
          },
          {
            type: "input",
            label: this.$t('in.appointmentkey'),
            disabled: true,
            props: "appointmentkey"
          },
          {
            type: "input",
            label: this.$t('in.door'),
            props: "door"
          },
          {
            type: "date",
            label: this.$t('in.arrivaldatetime'),
            props: "arrivaldatetime"
          },
          {
            type: "date",
            label: this.$t('in.actualdeparturedate'),
            props: "actualdeparturedate"
          },
          {
            type: "input",
            label: this.$t('config.phone'),
            props: "carrierphone"
          },
          {
            type: "input",
            label: this.$t('bill.country'),
            props: "carriercountry"
          },
          {
            type: "input",
            label: this.$t('in.trailernumber'),
            props: "trailernumber"
          },
          {
            type: "input",
            label: this.$t('in.trailerdesc'),
            disabled: true,
            props: ""
          },
          {
            type: "input",
            label: this.$t('in.trailerowner'),
            props: "trailerowner"
          },
          {
            type: "input",
            label: this.$t('in.drivername'),
            props: "drivername"
          },
          {
            type: "input",
            label: this.$t('in.temperature'),
            props: "temperature"
          }
      ],
      rules: {
        carrierphone: [
          { validator: this.carrierphone, trigger: 'blur' },
        ],
        temperature: [
          { validator: this.temperature, trigger: 'blur' },
        ],
      },
    };
  },
  methods: {
    temperature (rule, value, callback) {
      if (!value) {
        callback();
      } else {
        var re = /[^0-9.]/;
        let te = value;
        let flag = re.test(te)
        if (!flag) {
          if (te.length > 3) {
            this.$message.error(this.$t('app.maxMsg',{no:3}))
            this.inputData[rule.field] = ""
            callback(new Error());
          } else {
            callback();
          }
        } else {
          this.$message.error(this.$t('app.inputGreaterZeroNumberPlease'))
          this.inputData[rule.field] = ""
          callback(new Error());
        }
      }
    },
    carrierphone (rule, value, callback) {
      if (!value) {
        callback();
      } else {
        var re = /^[0-9]*$/;
        let te = value;
        let flag = re.test(te)
        if (flag) {
          callback();
        } else {
          this.$message.error(this.$t('app.inputGreaterZeroNumberPlease'))
          this.inputData[rule.field] = ""
          callback(new Error());
        }
      }
    },
    setdata (data, close,listId) {
      if(listId == 'carrierkey'){
        this.inputData.carrierkey = data.storerkey;
        this.inputData.carriername = data.company;
        this.inputData.carrieraddress1 = data.address1;
        this.inputData.carrieraddress2 = data.address2;
        this.inputData.carriercity = data.city;
        this.inputData.carrierphone = data.phone1;
        this.inputData.carrierstate = data.state;
        this.inputData.carrierzip = data.zip;
        this.inputData.carriercountry = data.country;
        this.$set(this.inputData, "temperature", null)
      }
      close(false);
    }
  },
  mounted () {
  },
};
</script>

<style scoped>
</style>

